// 查询统计模块api
import Mock from 'mockjs'
const List = []
const count = 1
for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id: i + 1,
    'bankname|1': ['龙华支行', '南山支行', '罗湖支行', '福田支行'],
    'hallname|1': ['大厅一', '大厅二', '大厅三', '大厅四'],
    'windowname|1': ['窗口一', '窗口二', '窗口三', '窗口四'],
    'mename|1': ['机构一', '机构二', '机构三', '机构四'],
    'personname|1': ['aaa', 'bbb', 'ccc', 'ddd'],
    'stars|1': ['1', '3', '5'],
    bestsatisfied: '9', // 非常满意
    satisfied: '5', // 满意
    totlesatisfied: '14',
    basepleasure: '3', // 基本满意
    displeasure: '1', // 不满意
    totledispleasure: '1',
    notevaluated: '11',
    totle: '26',
    date1: Mock.Random.date(),
    date2: Mock.Random.date(),
    emp: Mock.Random.integer(1, 10000),
    username: Mock.Random.cname(),
    'result|1': ['满意', '不满意']
  }))
}

export default [
  {
    url: '/querystats/getdata',
    type: 'get',
    response: config => {
      const { importance, type, title, page = 1, limit = 20, sort } = config.query
      let mockList = List.filter(item => {
        if (importance && item.importance !== +importance) return false
        if (type && item.type !== type) return false
        if (title && item.title.indexOf(title) < 0) return false
        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }
      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  },
  {
    url: '/querystats/getInfo',
    type: 'get',
    response: config => {
      const { importance, type, title, page = 1, limit = 20, sort } = config.query
      let mockList = List.filter(item => {
        if (importance && item.importance !== +importance) return false
        if (type && item.type !== type) return false
        if (title && item.title.indexOf(title) < 0) return false
        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }
      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  },
  {
    url: '/querystats/getPermission',
    type: 'get',
    response: config => {
      return {
        code: 20000,
        data: [{
          'id': '1',
          'label': '龙华支行',
          'type': 'bank',
          'children': [{
            'id': '1-1',
            'label': '大厅一',
            'type': 'halls',
            'children': [{
              'id': '1-1-1',
              'label': '窗口一',
              'type': 'windows'
            }, {
              'id': '1-1-2',
              'type': 'windows',
              'label': '窗口一'
            }]
          }, {
            'id': '1-2',
            'label': '大厅二',
            'type': 'halls',
            'children': [{
              'id': '1-2-1',
              'type': 'windows',
              'label': '窗口一'
            }, {
              'id': '1-2-2',
              'type': 'windows',
              'label': '窗口二'
            }]
          }]
        }, {
          'id': '2',
          'label': '南山支行',
          'type': 'bank',
          'children': [{
            'id': '2-1',
            'type': 'halls',
            'label': '大厅一'
          }, {
            'id': '2-2',
            'type': 'halls',
            'label': '大厅二'
          }]
        }, {
          'id': '3',
          'label': '福田支行',
          'type': 'bank',
          'children': [{
            'id': '3-1',
            'type': 'halls',
            'label': '大厅一'
          }, {
            'id': '3-2',
            'type': 'halls',
            'label': '大厅二'
          }]
        }]

      }
    }
  }

]

